<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: 32104
  Date: 2024/6/8
  Time: 下午5:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询</title>
    <link href="../../CSS/Third.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="d3">
    <table>
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>地址</th>
            <th>电话</th>
            <th>性别</th>
        </tr>
        <%
            String id = request.getParameter("ID");
            if (id != null) {
                try {
                    Class.forName("com.mysql.cj.jdbc.Driver");
                    String url = "jdbc:mysql://localhost:3306/student?serverTimezone=Asia/Shanghai";
                    String userName = "root";
                    String password = "root";
                    Connection connection = DriverManager.getConnection(url, userName, password);
                    String selectSQL = "select * from user_info where id=?;";
                    PreparedStatement preparedStatement = connection.prepareStatement(selectSQL);
                    preparedStatement.setString(1, id);
                    ResultSet resultSet = preparedStatement.executeQuery();
                    while (resultSet.next()) {
                        int id1 = resultSet.getInt("id");
                        String name = resultSet.getString("name");
                        int age = resultSet.getInt("age");
                        String address = resultSet.getString("address");
                        String phone = resultSet.getString("phone");
                        int sex = resultSet.getInt("sex");
                        out.print("<tr>");
                        out.print("<td>" + id1 + "</td>");
                        out.print("<td>" + name + "</td>");
                        out.print("<td>" + age + "</td>");
                        out.print("<td>" + address + "</td>");
                        out.print("<td>" + phone + "</td>");
                        if (sex == 0) {
                            out.print("<td>" + "女" + "</td>");
                        } else {
                            out.print("<td>" + "男" + "</td>");
                        }
                        out.print("</tr>");
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
        %>
        <script>
            alert("您输入的ID格式不对,请重试!")
        </script>
        <%
                response.sendRedirect("../select/select.jsp");
            }
        %>
    </table>
</div>
<button type="button" style="border-color: chartreuse;background-color: aquamarine;font-family: cursive;border-radius: 10px;"><a href="../select/select01.jsp" style="text-decoration: none;color: black;">返回</a></button>
</body>
</html>



